package com.guet.controller.teacher;

import com.guet.DTO.NotificationDTO;
import com.guet.DTO.NotificationDraftDTO;

import com.guet.Entity.NotificationDraft;
import com.guet.VO.NotificationDraftVO;
import com.guet.mapper.NotificationMapper;
import com.guet.result.PageResult;
import com.guet.result.Result;
import com.guet.service.NotificationService;

import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("teacherNotificationController")
@RequestMapping("teacher/notification")
@Slf4j
@CrossOrigin
public class NotificationController {
    @Autowired
    private NotificationService notificationService;
    @Autowired
    private NotificationMapper notificationMapper;

    /**
     * 获取公告
     *
     * @param notificationDTO
     * @return
     */
    @PostMapping
    public Result<PageResult> queryNotification(@RequestBody NotificationDTO notificationDTO) {
        log.info("notificationDTO: {}", notificationDTO);
        PageResult result = notificationService.list(notificationDTO);
        return Result.success(result);
    }

    /**
     * 保存公告草稿
     *
     * @param notificationDraftDTO
     * @return
     */
    @PostMapping("draft")
    public Result<Object> saveTopicDraft(@RequestBody NotificationDraftDTO notificationDraftDTO) {
        log.info("topicSaveDTO: {}", notificationDraftDTO);
        notificationService.saveNotificationDraft(notificationDraftDTO);
        return Result.success();
    }

    /**
     * 获取草稿
     * @return
     */
    @GetMapping("draft")
    public Result<NotificationDraftVO> getNotificationDraft() {
        NotificationDraftVO result = notificationService.getNotificationDraft();
        return Result.success(result);
    }

    /**
     * 发布公告
     * @return
     */
    @PostMapping("publish")
    public Result<Object> publish(@RequestBody NotificationDraftDTO notificationDraftDTO) {
        notificationService.publish(notificationDraftDTO);
        return Result.success();
    }

    @DeleteMapping
    public Result<Object> deleteNotification(String id) {
        log.info("id: {}", id);
        notificationService.deleteNotification(id);
        return Result.success();
    }
}
